package com.lzx.adx.report.util.helper;

import cn.hutool.core.util.URLUtil;
import com.alibaba.fastjson.JSON;
import com.lzx.adx.report.dto.AccountDTO;
import com.lzx.adx.report.dto.ReportDTO;
import com.lzx.adx.report.model.tencent.request.TencentReportRequest;
import com.lzx.adx.report.model.wifi.WifiRequest;
import com.lzx.adx.report.util.MacroReplacement;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class TencentHelper {


    public static String handUrl(ReportDTO reportDTO, AccountDTO accountDTO) {
        TencentReportRequest tencentReportRequest= JSON.parseObject(reportDTO.getExtend(),TencentReportRequest.class) ;


        long time = System.currentTimeMillis();
        Map<String,String> map=new HashMap<>();
        map.put("REQUEST_ID",reportDTO.getBizRequestId());
        map.put("OAID","");
        map.put("IP",tencentReportRequest.getIp());
        map.put("OS","0");
        map.put("MTS",String.valueOf(time));
        map.put("IMEI","");
        map.put("IMEI_MD5", StringUtils.isNotBlank(tencentReportRequest.getMuid())?tencentReportRequest.getMuid():"");
        map.put("OAID_MD5",StringUtils.isNotBlank(tencentReportRequest.getHash_oaid())?tencentReportRequest.getHash_oaid():"");
        map.put("IDFA","");
        map.put("IDFA_MD5","");
        map.put("UA",URLUtil.encode(reportDTO.getUser_agent()));
        map.put("MODEL","");
        map.put("MAC","");
        map.put("MAC_MD5","");
        map.put("MAC1_MD5","");
        map.put("CAID","");
        map.put("TRAFFIC_SOURCE","");



        String allCabackUrl = String.format(accountDTO.getDspCallbackUrl(), reportDTO.getBizRequestId());

        map.put("CALLBACK_URL",allCabackUrl);
        log.info("完整的回调地址{}",allCabackUrl);
        return   MacroReplacement.replaceMacros(accountDTO.getDspReportUrl(),map);
    }
}
